IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace : EntityQuery<T> Class |
'Declaration
Public Class EntityQuery(Of T) Inherits EntityQuery Implements IEntityQuery, IEntityQuery(Of T), ISupportsQueryCache, ITypedEntityQuery, System.Collections.Generic.IEnumerable(Of T), System.Collections.IEnumerable, System.ICloneable, System.Linq.IOrderedQueryable, System.Linq.IOrderedQueryable(Of T), System.Linq.IQueryable, System.Linq.IQueryable(Of T), System.Linq.IQueryProvider
'Usage
Dim instance As EntityQuery(Of T)
public class EntityQuery<T> : EntityQuery, IEntityQuery, IEntityQuery<T>, ISupportsQueryCache, ITypedEntityQuery, System.Collections.Generic.IEnumerable<T>, System.Collections.IEnumerable, System.ICloneable, System.Linq.IOrderedQueryable, System.Linq.IOrderedQueryable<T>, System.Linq.IQueryable, System.Linq.IQueryable<T>, System.Linq.IQueryProvider
An EntityQuery<T> can be executed in several ways. First, you can use LINQ deferred execution: that is the query is automatically executed as you begin iterating over the query variable using a foreach statement. The query's EntityQuery.EntityManager and EntityQuery.QueryStrategy determine how the query results are obtained.
You can force immediate execution of the EntityQuery<T> by calling either ToList() or ToArray() on the query. This again will use the query's EntityQuery.EntityManager and EntityQuery.QueryStrategy to determine how the query results are obtained.
You can also use one of the many ExecuteQuery methods defined on the EntityManager. These methods give you additonal control over how the query is executed, but are functionally equivalent to using either the standard deferred and immediate methods of LINQ.
DevForce supports all the LINQ standard query operators supported by the Microsoft Entity Framework (EF), as well as some operators not yet supported in EF. Check the DevForce Developer's Guide for more information.
An EntityQuery<T> can be used in either 2-tier or n-tier DevForce deployments without modification. In n-tier implementations DevForce will serialize the query to the BOS for execution and return appropriate results to the client. Note that queries returning anonymous types can also be used in either 2-tier or n-tier.
// Simple queries in LINQ query and method syntax. public void SimpleQueries() { AW2000Model.Manager mgr = new AW2000Model.Manager(); // 1 - retrieve all customers using LINQ query syntax. // (Careful, this may be alot of data ...) EntityQuery<Customer> q1 = from c in mgr.Customers select c; List<Customer> results1 = q1.ToList(); // 2- retrieve all customers using LINQ method syntax. EntityQuery<Customer> q2 = mgr.Customers; List<Customer> results2 = q2.ToList(); // 3 - retrieve customers with criteria EntityQuery<Customer> q3 = from c in mgr.Customers where c.CustomerID < 20 select c; List<Customer> results3 = q3.ToList(); EntityQuery<Customer> q4 = mgr.Customers.Where(c => c.CustomerID < 20); List<Customer> results4 = q4.ToList(); } // Query projection returning an anonymous type. public void QueryAnonymousTypes() { AW2000Model.Manager mgr = new AW2000Model.Manager(); // Return an anonymous type of {custid, salesorders} var q1 = from c in mgr.Customers where (c.CustomerID == 1 || c.CustomerID == 2) select new { c.CustomerID, c.SalesOrderHeaders }; var results1 = q1.ToList(); // Same as above, using method syntax. var q2 = mgr.Customers.Where(c => c.CustomerID == 1 || c.CustomerID == 2) .Select(c => new { c.CustomerID, c.SalesOrderHeaders }); var results2 = q2.ToList(); } public void QueryWithOrderBy() { AW2000Model.Manager mgr = new AW2000Model.Manager(); EntityQuery<Customer> q1 = from c in mgr.Customers where c.CustomerID < 10 orderby c.CustomerID descending select c; // Let's call ExecuteQuery directly. IEnumerable<Customer> results1 = mgr.ExecuteQuery<Customer>(q1); // Same as above EntityQuery<Customer> q2 = mgr.Customers .Where(c => c.CustomerID < 10) .OrderByDescending(c => c.CustomerID); IEnumerable<Customer> results2 = mgr.ExecuteQuery<Customer>(q2); } // More complex queries - nested criteria and use of .Include. public void QueryNestedWithInclude() { AW2000Model.Manager mgr = new AW2000Model.Manager(); // Return customers based on nested criteria. var q1 = from c in mgr.Customers where c.SalesPerson.SalesLastYear > 2000000 select c; q1 = q1.Include("SalesPerson"); var results1 = q1.ToList(); // Equivalent query in method syntax. var q2 = mgr.Customers.Where(c => c.SalesPerson.SalesLastYear > 2000000) .Include("SalesPerson"); var results2 = q2.ToList(); }
System.Object
IdeaBlade.EntityModel.EntityQuery
IdeaBlade.EntityModel.EntityQuery<T>
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2